﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;

namespace HenIT.BizTalk
{
    internal static class BizTalkUtils
    {
        private static string bizTalkAdminKey = "Software\\Microsoft\\BizTalk Server\\3.0\\Administration";

        public static string GetCurrentBizTalkSqlServer()
        {
            string sqlServer = ".";
            RegistryKey key = null;
            try
            {                
                key = Registry.LocalMachine.OpenSubKey(bizTalkAdminKey, true);
                sqlServer = key.GetValue("MgmtDBServer").ToString();
                key.Close();
            }
            catch
            {
                if (key != null)
                    key.Close();
                throw;
            }
            return sqlServer;
        }

        public static string GetCurrentBizTalkMgmtDb()
        {
            string mgmtDb = "BizTalkMgmtDb";
            RegistryKey key = null;
            try
            {
                
                key = Registry.LocalMachine.OpenSubKey(bizTalkAdminKey, true);
                mgmtDb = key.GetValue("MgmtDBName").ToString();
                key.Close();
            }
            catch 
            {
                if (key != null)
                    key.Close();
                throw;
            }
            return mgmtDb;
        }
        
    }
}
